package ch.ti.kmltomap;

import java.io.InputStream;

import org.xmlpull.v1.XmlPullParser;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class IconStyle extends ColorStyle{
	
	private Bitmap icon = null;
	
	public IconStyle(String url){
		this.icon = UrlUtils.getBitmapFromURL(url);
	}
	
	public IconStyle(InputStream is){
		this.icon = BitmapFactory.decodeStream(is);
	}
	
	public IconStyle(XmlPullParser xpp){
		try{
			this.id = xpp.getAttributeValue(null, "id");
			int eventType = xpp.next();
			String tagName = "";
			while (eventType != XmlPullParser.END_DOCUMENT) {
				if(eventType == XmlPullParser.START_TAG){
					tagName = xpp.getName();
				}
				if(eventType == XmlPullParser.TEXT){
					if(tagName.equals("color")){
						this.color = xpp.getText().trim();
					}else if(tagName.equals("href")){
						this.icon = UrlUtils.getBitmapFromURL(xpp.getText().trim());
					}
				}else if(eventType == XmlPullParser.END_TAG){
					if(xpp.getName().equals("IconStyle")){
						break;
					}
				}
				eventType = xpp.next();
			}
		}catch (Exception e) {
		}	
	}
	
	public Bitmap icon(){
		return icon;
	}
	
	public void icon(Bitmap bitmap){
		this.icon = bitmap;
	}
}
